﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace RestfulApi.Filters
{
    public class MyActionFilterAttribute : Attribute, IActionFilter
    {
        public MyActionFilterAttribute(ILogger<MyActionFilterAttribute> logger)
        {
            Logger = logger;
        }

        public ILogger<MyActionFilterAttribute> Logger { get; }

        public void OnActionExecuted(ActionExecutedContext context)
        {
            //Logger.LogInformation("OnActionExecuted  executes.");
            //throw new Exception("OnActionExecuted");// 可以
        }

        public void OnActionExecuting(ActionExecutingContext context)
        {
            //Logger.LogInformation("OnActionExecuting  executes.");
            //throw new Exception("OnActionExecuting"); // 可以
        }
    }
}
